﻿<!--Files Operator version 0.6 -->

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="filetree0.aspx.cs" Inherits="FileTree" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=8" />
	<title>FileTree</title>
	<script type="text/javascript" src="Scripts/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="Scripts/jquery.query-2.1.7.js"></script>
	<script type="text/javascript" src="Scripts/Script.js"></script>
	<script type="text/javascript" src="Scripts/Serialize.js"></script>
	<script type="text/javascript" src="Scripts/tree.js"></script>
	<script type="text/javascript" src="Scripts/RepeaterHelper2.js"></script>
	<link type="text/css" href="Styles/ArrangerFrame.css" rel="stylesheet" />
	<link type="text/css" href="Styles/tree.css" rel="stylesheet" />

	<script type="text/javascript">		

//<![CDATA[
		var StatusBarDiv;
		var t = 10000, timer;  //自动刷新间隔
		var RootNode;
		var PageTitlesFloater, PageTitlesOuter, PageTitlesDoor;
		var Pages = new Object();
		var CurentPageTitle, CurentPage;
		var RootId = "<%=Request.QueryString["test"]=="true"?"FakeTree":"SiteBrowseTree"%>";
		function pageOnload() {
			//<%if (Page.User.Identity.IsAuthenticated){%>
			$tree.init({ "RootId": RootId, "contextmenu": true });
			$tree.LoadChildren(null, document.getElementById(RootId));
			//<%}%>
			return;

			StatusBarDiv = document.getElementById("StatusBar");
			
			PageTitlesDoor = $("#PageTitlesDoor")[0];
			PageTitlesOuter = $("#PageTitlesOuter")[0];
			PageTitlesFloater = $("#PageTitlesFloater")[0];
			CurentPageTitle = $("#StartPageTitle")[0];
			CurentPage = $("#StartPage")[0];
			Pages.set(CurentPageTitle.id, [CurentPageTitle, CurentPage]);
		}

		var ajaxLoginUrl = "AjaxLogin.ashx";
		function Login_onsubmit() {
			var postbody = "username=" + jQuery("#username").val() + "&password=" + jQuery("#password").val();
			jQuery.ajax({
				type: "POST",
				url: ajaxLoginUrl + "?action=login",
				data: postbody,
				dataType: "json",
				success: function (Json) {
					if (Json.Result) {
						$("#loginstatus")[0].innerHTML = "登录成功" + "<input type=\"button\" value=\"登出\" onclick=\"logout();\" />";
						$("#loginDiv")[0].parentNode.removeChild($("#loginDiv")[0]);
						$tree.init({ "RootId": RootId, "contextmenu": true });
						$tree.LoadChildren(null, document.getElementById(RootId));
					} else {
						$("#loginstatus")[0].innerHTML = "登录失败";
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) { if (typeof XMLHttpRequest == "object") alert(XMLHttpRequest.responseText == "" ? textStatus : XMLHttpRequest.responseText); else alert(XMLHttpRequest); }
			});
			return false;
		}
		function logout() {
			jQuery.ajax({
				type: "POST",
				url: ajaxLoginUrl + "?action=logout",
				data: "",
				dataType: "json",
				success: function (Json) {
					if (Json.Result) {
						location.href = location.pathname;
					} else {
						$("#loginstatus")[0].innerHTML = "登出失败";
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) { if (typeof XMLHttpRequest == "object") alert(XMLHttpRequest.responseText == "" ? textStatus : XMLHttpRequest.responseText); else alert(XMLHttpRequest); }
			});
			return false;
		}
		function SetTime_onclick(o) {
			window.clearInterval(timer);
			var x = parseInt(o.previousSibling.previousSibling.value) * 1000;
			t = isNaN(x) ? t : x;
			timer = window.setInterval("Refresh()", t);
		}
		function Download(o) {
			if (o.parentNode.parentNode.className == ObjectListClass) {
				var path = encodeURIComponent(o.parentNode.id);
				var DownWin = window.open(location.href + "?act=download&path=" + path);
				DownWin.onload = function () { DownWin.close(true); };
			}
			return false;
		}
		function ViewSeleted() {
			if (OperationDiv.parentNode.parentNode.className == ObjectListClass) {
				window.open(OperationDiv.childNodes[2].firstChild.href);
			}
		}
		function open_win() {
			var newWin = window.open("HTMLPage2.htm", "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
			//newWin.window.blur();
			//window.focus();
		}
		function PageTitlesMoveRight() {
			var marginLeft = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]);
			var HiddenLength = PageTitlesFloater.clientWidth + marginLeft * 16 - PageTitlesDoor.clientWidth;
			if (HiddenLength > 256) {
				PageTitlesOuter.style.marginLeft = (marginLeft - 16) + "em";
			} else if (HiddenLength <= 256) {
				PageTitlesOuter.style.marginLeft = (marginLeft - HiddenLength / 16) + "em";
			} else { }
		}
		function PageTitlesMoveLeft() {
			var marginLeft = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]);
			var HiddenLength = PageTitlesFloater.clientWidth + marginLeft * 16 - PageTitlesDoor.clientWidth;
			if (marginLeft * 16 < -256) {
				PageTitlesOuter.style.marginLeft = (marginLeft + 16) + "em";
			} else if (marginLeft * 16 >= -256) {
				PageTitlesOuter.style.marginLeft = "0em";
			}
		}
		function PageClose(PageId) {
			var TitleDiv = Pages.get(PageId)[0];
			var PageDiv = Pages.get(PageId)[1];
			TitleDiv.parentNode.removeChild(TitleDiv);
			PageDiv.parentNode.removeChild(PageDiv);
			Pages.unset(PageId);
			if (CurentPageTitle.id == PageId) {
				if (Pages.values().length > 0) {
					CurentPageTitle = (Pages.values()[Pages.values().length - 1])[0];
					CurentPage = (Pages.values()[Pages.values().length - 1])[1];
					CurentPageTitle.className = "PageTitleActive";
					CurentPage.style.display = "";
				}
			}
			return false;
		}
		function SwitchPage(PageId) {
			var TitleDiv = Pages.get(PageId)[0];
			if (CurentPageTitle.id != PageId) {
				var PageDiv = Pages.get(PageId)[1];
				CurentPageTitle.className = "PageTitle";
				CurentPage.style.display = "none";
				TitleDiv.className = "PageTitleActive";
				PageDiv.style.display = "";
				CurentPageTitle = TitleDiv;
				CurentPage = PageDiv;
			}
			var leftLength = 0;
			for (var i = 0; i < TitleDiv.parentNode.childNodes.length; i++) {
				if (TitleDiv == PageTitlesFloater.childNodes[i]) break;
				leftLength += PageTitlesFloater.childNodes[i].clientWidth;
			}
			var marginLeftPx = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]) * 16;
			if (leftLength + marginLeftPx < 0) {
				PageTitlesOuter.style.marginLeft = (-leftLength / 16) + "em";
			}
			var rightLength = leftLength + TitleDiv.clientWidth;
			if (rightLength > PageTitlesDoor.clientWidth - marginLeftPx) {
				PageTitlesOuter.style.marginLeft = (PageTitlesDoor.clientWidth - rightLength) / 16 + "em";
			}
		}
		function EditFile(o, CodePage) {
			var pathName = o.parentNode.id;
			var PageId = "Edit:" + pathName;
			if (Pages.keys().indexOf(PageId) == -1) {
				var PageTitle = document.createElement("div");
				PageTitle.id = PageId;
				PageTitle.onclick = function () { SwitchPage(this.id); };
				PageTitle.title = pathName;
				PageTitle.innerHTML = "<a href=\"#\" onfocus=\"this.blur();\" onclick=\"return false;\"><span class=\"PageCloseButton\" title=\"关闭\" onclick=\"return PageClose(this.parentNode.parentNode.id);\">×</span><span class=\"PageTitleBg0\"><span class=\"PageTitleBg1\"><span class=\"PageTitleBg2\">Page Title</span></span></span></a>";
				PageTitle.firstChild.lastChild.firstChild.firstChild.firstChild.data = pathName;
				PageTitlesFloater.insertBefore(PageTitle, PageTitlesFloater.firstChild);
				PageTitlesOuter.style.marginLeft = "0em";
				var Page = document.createElement("div");
				Page.className = "inside";
				Page.style.zIndex = 100;
				Page.style.overflow = "hidden";
				$("#ContentWindow")[0].appendChild(Page);
				var EditFrame = document.createElement("iframe");
				EditFrame.name = "EditFrame|" + pathName;
				EditFrame.src = "EditFile.aspx?path=" + encodeURIComponent(pathName) + "&CodePage=" + CodePage;
				EditFrame.frameBorder = "0";
				EditFrame.scrolling = "auto";
				EditFrame.style.width = "100%";
				EditFrame.style.height = "100%";
				EditFrame.style.position = "absolute";
				Page.appendChild(EditFrame);
				Pages.set(PageTitle.id, [PageTitle, Page]);
			}
			SwitchPage(PageId);
		}
		function UploadFiles(o) {
			var path = o.parentNode.id;
			var PageId = "Upload:" + path;
			if (Pages.keys().indexOf(PageId) == -1) {
				var PageTitle = document.createElement("div");
				PageTitle.id = PageId;
				PageTitle.onclick = function () { SwitchPage(this.id); };
				PageTitle.title = "上传至" + path;
				PageTitle.innerHTML = "<a href=\"#\" onfocus=\"this.blur();\" onclick=\"return false;\"><span class=\"PageCloseButton\" title=\"关闭\" onclick=\"return PageClose(this.parentNode.parentNode.id);\">×</span><span class=\"PageTitleBg0\"><span class=\"PageTitleBg1\"><span class=\"PageTitleBg2\">Page Title</span></span></span></a>";
				PageTitle.firstChild.lastChild.firstChild.firstChild.firstChild.data = "上传文件";
				PageTitlesFloater.insertBefore(PageTitle, PageTitlesFloater.firstChild);
				PageTitlesOuter.style.marginLeft = "0em";
				var Page = document.createElement("div");
				Page.className = "inside";
				Page.style.zIndex = 100;
				Page.style.overflow = "hidden";
				$("#ContentWindow")[0].appendChild(Page);
				var EditFrame = document.createElement("iframe");
				EditFrame.name = "UploadFrame|" + path;
				EditFrame.src = "UploadFiles.aspx?path=" + encodeURIComponent(path);
				EditFrame.frameBorder = "0";
				EditFrame.scrolling = "auto";
				EditFrame.style.width = "100%";
				EditFrame.style.height = "100%";
				EditFrame.style.position = "absolute";
				Page.appendChild(EditFrame);
				Pages.set(PageTitle.id, [PageTitle, Page]);
			}
			SwitchPage(PageId);
		}
//]]>
	</script>
</head>
<body onload="pageOnload()">
	<div id="OperationArea">
		<div id="CreateFolderDialog" style="visibility: hidden; position: absolute; z-index: 600; padding: 5px; background: #eee; border: #888 2px outset;">
			<form action="" onsubmit="CreateFolderSubmit(this);return false;">
			<div clase="DialogTitle">
				新建文件夹</div>
			<div>
				<input type="text" id="NewFolderName" /><br />
				<input type="submit" value="确定" />
				<input type="reset" value="取消" onclick="this.parentNode.parentNode.parentNode.style.visibility='hidden';" />
			</div>
			</form>
		</div>
	</div>
	<div id="MainBody">
		<div id="header">
			<h1>
				Files Operator 文件浏览器</h1>
		</div>
		<div id="loginBox">
			<%if (!Request.IsAuthenticated)
	 {%>
			<form id="Login" onsubmit="return Login_onsubmit()" action="">
			<div id="loginDiv">
				<label for="username">
					用户：</label><input type="text" id="username" name="username" value="admin" /><br />
				<label for="password">
					密码：</label><input type="password" id="password" name="password" value="adminer" /><br />
				<input id="submitbutton" type="submit" value="登录" />
			</div>
			</form>
			<%}%>
			<%if (Request.IsAuthenticated)
	 {%>
			<div>
				<input type="button" value="登出" onclick="logout();" />
			</div>
			<%}%>
			<div id="loginstatus">
			</div>
		</div>
		<div id="folderToolBar">
			<div class="padding">
				<input title="刷新" onclick="Refresh();" type="button" style="width: 36px; height: 36px; background: url(images/refresh.gif)" />
				<input disabled="disabled" type="button" title="删除" style="width: 36px; height: 36px; background: url(images/del.gif)" />
				<input disabled="disabled" type="button" title="复制" style="width: 36px; height: 36px; background: url(images/copy.gif)" />
				<input disabled="disabled" type="button" title="剪切" style="width: 36px; height: 36px; background: url(images/cut.gif)" />
				<input disabled="disabled" type="button" title="粘贴" style="width: 36px; height: 36px; background: url(images/paste.gif)" />
				<input disabled="disabled" type="button" title="压缩" style="width: 36px; height: 36px; background: url(images/RarAdd.gif)" />
				<input disabled="disabled" type="button" title="解压" style="width: 36px; height: 36px; background: url(images/RarExt.gif)" />
			</div>
		</div>
		<div id="folderDiv">
			<div class="inner">
				<div class="inside">
					<div id="<%=Request.QueryString["test"]=="true"?"FakeTree":"SiteBrowseTree"%>" style="padding-left: 0.5em;">
					</div>
				</div>
			</div>
		</div>
		<div id="PageTitles">
			<div id="PageTitlesList">
				▼</div>
			<div id="PageTitlesMoveLeft" onclick="PageTitlesMoveLeft();">
				﹤</div>
			<div id="PageTitlesMoveRight" onclick="PageTitlesMoveRight();">
				﹥</div>
			<div id="PageTitlesDoor">
				<div id="PageTitlesOuter">
					<div id="PageTitlesFloater">
						<div onclick="SwitchPage(this.id);" class="PageTitleActive" id="StartPageTitle" title="起始页">
							<a href="#" onfocus="this.blur();" onclick="return false;">
								<!--<span class="PageCloseButton" title="关闭" onclick="return PageClose(this.parentNode.parentNode.id);">×</span>-->
								<span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">起始页</span></span></span></a></div>
						<!--<div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题</span></span></span></a></div>
						<div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题2</span></span></span></a></div>
						<div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题9</span></span></span></a></div>-->
					</div>
				</div>
			</div>
		</div>
		<div id="filesDiv">
			<div class="inner" id="ContentWindow">
				<div id="StartPage" class="inside">
					<div id="StartPageContent" style="padding: 0.5em;">
						<div>
							<a href="javascript:location.href=$.query.set('test','false');" title="File Tree">File Tree</a> <a href="javascript:location.href=$.query.set('test','true');" title="Fake Tree">Fake Tree</a>
						</div>
						<hr />
						<div>
							<textarea cols="80" rows="10" id="logWatcher"></textarea>
						</div>
						<div>
							<input type="button" value="show log" onclick="$('#logWatcher').val(logs.join('\n'));" />
						</div>
						<hr />
						<div id="PathBox">
							<div>
								<span>当前位置：</span><input type="text" id="FolderPath" name="FolderPath" size="60" /><input type="button" value="Go" /></div>
							<div>
								<span>操作对象：</span><input type="text" id="FilePath" name="FilePath" size="40" /><input type="button" value="Go" /></div>
						</div>
						<div id="checkedbox">
						</div>
						<div>
							<form action="" target="_blank">
							<input type="hidden" name="act" value="remotedownload" />
							<input type="text" name="url" id="RemoteDownload" value="http://" size="80" />
							<input type="submit" name="" value="下载" />
							</form>
						</div>
						<hr />
					</div>
				</div>
			</div>
		</div>
		<div id="footer">
			<div id="footerInner">
				<span id="StatusBar" style="text-align: center;">页面执行时间：<%=PageSpendTime.TotalMilliseconds%>
					毫秒 </span>
			</div>
		</div>
	</div>
</body>
</html>
